<?php

namespace WeForge\Runtime;

use Swoole\Coroutine;

class Context
{
    /**
     * @var array
     */
    protected static $pool = [];

    /**
     * @return array|null
     */
    public static function all()
    {
        return self::$pool[Coroutine::getCid()] ?? null;
    }

    /**
     * @param string $key
     * @param string $value
     *
     * @return void
     */
    public static function env($key, $value)
    {
        $cid = Coroutine::getCid();

        self::$pool[$cid]['env'][$key] = $value;
    }

    /**
     * @return void
     */
    public static function destroy()
    {
        unset(self::$pool[Coroutine::getCid()]);
    }
}
